package Chapter06;

/**
 * 线程插队运行
 * join()方法可以让调用该方法的线程优先于其他线程执行,实现类似插队的效果,
 * 插队线程执行完毕,其他线程会继续运行.
 * Created by a on 2017/6/11.
 */
public class Test131 {
    public static void main(String[] args) {
        Thread thread = new Thread(new EmergencyThread());
        thread.start();
        for (int i =1 ; i < 6; i++){
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("正常情况:"+i+"号出发!");
            try {
                thread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

class EmergencyThread implements Runnable {

    @Override
    public void run() {
        for (int i =1; i <6;i++){
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("紧急情况:"+i+"号车出发!");
        }
    }
}